package com.itheima.tlias.utils;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

public class UserThreadLocal {

    private static final ThreadLocal<Object> userThreadLocal = new ThreadLocal<>();
    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    public static class UserInfo {
        private Integer id;
        private String name;
    }
    /**
     * 从当前线程获取UserInfo
     */
    public static UserInfo getUserInfo() {
        return (UserInfo) userThreadLocal.get();
    }

    /**
     * 向当前线程保存UserInfo
     */
    public static void setUserInfo(UserInfo userInfo) {
        userThreadLocal.set(userInfo);
    }

    /**
     * 从当前线程删除UserInfo
     */
    public static void removeUserInfo() {
        userThreadLocal.remove();
    }

}